package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.CPService;
import com.yixun.qfbao.apidto.EditCustomerInfoReqDto;
import com.yixun.qfbao.apidto.EditCustomerInfoResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.EditCustomerInfoReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import com.yixun.qfbao.xf.service.CustomerPremisesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EditCustomerInfoHander extends CommonAbstractHander {

    private static final Logger logger = LoggerFactory.getLogger(EditCustomerInfoHander.class);

    @Autowired
    private CPService cpService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO baseRequestDTO) {
        EditCustomerInfoReqVo reqVo = (EditCustomerInfoReqVo) baseRequestDTO;
        EditCustomerInfoReqDto reqDto = reqVo.getParams();
        BaseResponseDTO<EditCustomerInfoResDto> res = new BaseResponseDTO();
        try {
            EditCustomerInfoResDto resDto = cpService.editCustomerInfo(reqDto);
            res.setResult(resDto.getResult());
            res.setResData(resDto);
        } catch (TServerException t) {
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg(t.getErrorMsg());
        } catch (Exception e) {
            logger.error("EditCustomerInfoHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("系统异常，请稍后再试！");
        }
        return res;
    }
}
